package com.md.api.controller;

import com.md.api.annotation.NoRepeatSubmit;
import com.md.api.common.utils.StringUtils;
import com.md.api.entity.*;
import com.md.api.entity.dto.ComposeQueryDto;
import com.md.api.entity.dto.ProductBuyDto;
import com.md.api.entity.dto.SkuDetailDto;
import com.md.api.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Slf4j
@RequestMapping("/product")
@RestController
public class ProductController {


	@Resource
	ProductService productSevice;



	@RequestMapping("/page")
	@ResponseBody
	public HttpResult page(@RequestBody ComposeQueryDto qto) {

		return productSevice.page(qto);
	}

	//推荐产品
	@RequestMapping("/recommend")
	@ResponseBody
	public HttpResult recommend(@RequestBody ComposeQueryDto qto) {

		return productSevice.recommend(qto);
	}

	@RequestMapping("/spuDetail")
	@ResponseBody
	public HttpResult detail(@RequestBody PdSpu spu) {

		return productSevice.spuDetail(spu);
	}

	@RequestMapping("/skuDetail")
	@ResponseBody
	public HttpResult skuDetail(HttpServletRequest request,@RequestBody SkuDetailDto dto) {

		return productSevice.skuDetail(request,dto);
	}

	//加入购物车
	@RequestMapping("/addShoppingCart")
	@ResponseBody
	public HttpResult addShoppingCart(HttpServletRequest request,@RequestBody ShoppingCart shoppingCart) {
		if (null==shoppingCart.getNumCount()|| StringUtils.isEmpty(shoppingCart.getSpuId())||StringUtils.isEmpty(shoppingCart.getSkuId())){
			return HttpResult.PARAM_ERROR;
		}
		return productSevice.addShoppingCart(request,shoppingCart);
	}

}
